//
//  GroupMessageTableViewCell.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/3/31.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "GroupMessageTableViewCell.h"
#import "NetStatusHandle.h"

@interface GroupMessageTableViewCell ()

@property (nonatomic, strong) NSMutableArray *myMarkArray;

@end

@implementation GroupMessageTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addMySubview];
    }
    return self;
}

// 构建视图
- (void)addMySubview
{
    // 小组头像
    self.groupImageV = [[UIImageView alloc] initWithFrame:CGRectMake(16 * kAdjustParamater, 18 * kAdjustParamater, 40 * kAdjustParamater, 40 * kAdjustParamater)];
    self.groupImageV.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    self.groupImageV.layer.cornerRadius = self.groupImageV.width / 2;
    self.groupImageV.layer.masksToBounds = YES;
    [self.contentView addSubview:_groupImageV];
    
    // 小组名称
    self.xiaozuMingZiLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.groupImageV.right + 7 * kAdjustParamater, 13 * kAdjustParamater, 50 * kAdjustParamater, 11 * kAdjustParamater)];
  //    self.xiaozuMingZiLabel.backgroundColor = [UIColor redColor];
    self.xiaozuMingZiLabel.text = @"小组名称";
    self.xiaozuMingZiLabel.font = [UIFont systemFontOfSize:12 * kAdjustParamater];
    [self.contentView addSubview:_xiaozuMingZiLabel];
    
    // 名字
    self.groupNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xiaozuMingZiLabel.right + 6 * kAdjustParamater, self.xiaozuMingZiLabel.top, 50 * kAdjustParamater, 11 * kAdjustParamater)];
    //   self.nameLabel.backgroundColor = [UIColor redColor];


    self.groupNameLabel.font = [UIFont systemFontOfSize:12 * kAdjustParamater];
    [self.contentView addSubview:_groupNameLabel];
    
//    // 性别图片
//    self.genderImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.groupNameLabel.right + 8 * kAdjustParamater, self.groupNameLabel.top + 1 * kAdjustParamater, 13 * kAdjustParamater, 13 * kAdjustParamater)];
//    //    self.genderImageView.backgroundColor = [UIColor redColor];
//    [self.contentView addSubview:_genderImageView];
    
    // 小组介绍
    self.sampleIntroduceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xiaozuMingZiLabel.left, self.xiaozuMingZiLabel.bottom + 30 * kAdjustParamater, 300 * kAdjustParamater, 11 * kAdjustParamater)];
  //    self.sampleIntroduceLabel.backgroundColor = [UIColor redColor];
    self.sampleIntroduceLabel.text = @"小组介绍";
    self.sampleIntroduceLabel.font = [UIFont systemFontOfSize:12 * kAdjustParamater];
    self.sampleIntroduceLabel.textColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
    [self.contentView addSubview:_sampleIntroduceLabel];
    
   
    
    // 关注小组
//    self.attentionGroupButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    self.attentionGroupButton.backgroundColor = [UIColor whiteColor];
//    self.attentionGroupButton.frame = CGRectMake(240 * kAdjustParamater, 27 * kAdjustParamater, 50 * kAdjustParamater, 20 * kAdjustParamater);
//    [self.attentionGroupButton setTitle:@"+关注" forState:UIControlStateNormal];
//    [self.attentionGroupButton setTitleColor:[UIColor colorWithRed:222 / 255.0 green:138 / 255.0 blue:30 / 255.0 alpha:1] forState:UIControlStateNormal];
//    [self.attentionGroupButton.layer setBorderWidth:1];
//    self.attentionGroupButton.titleLabel.font = [UIFont systemFontOfSize:13 * kAdjustParamater];
//    self.attentionGroupButton.layer.cornerRadius = 3 * kAdjustParamater;
//    self.attentionGroupButton.layer.borderColor =[[[UIColor blackColor] colorWithAlphaComponent:0.3] CGColor];
//    [self.contentView addSubview:_attentionGroupButton];
    
    // 添加小组
    self.addGroupButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.addGroupButton.backgroundColor = [UIColor whiteColor];
    self.addGroupButton.frame = CGRectMake(280 * kAdjustParamater, 25 * kAdjustParamater, 70 * kAdjustParamater, 25 * kAdjustParamater);
    [self.addGroupButton setTitle:@"申请入组" forState:UIControlStateNormal];
    [self.addGroupButton setTitleColor:[UIColor colorWithRed:222 / 255.0 green:138 / 255.0 blue:30 / 255.0 alpha:1] forState:UIControlStateNormal];
    [self.addGroupButton.layer setBorderWidth:1];
    self.addGroupButton.titleLabel.font = [UIFont systemFontOfSize:14 * kAdjustParamater];
    self.addGroupButton.layer.cornerRadius = 3 * kAdjustParamater;
    self.addGroupButton.layer.borderColor = [[[UIColor blackColor] colorWithAlphaComponent:0.3] CGColor];
    [self.contentView addSubview:_addGroupButton];
    
    
}

- (void)setModel:(CeShiModelOfGroupMessage *)model
{
    // 小组标签
    self.myMarkArray = [NSMutableArray arrayWithArray: [model valueForKey:@"mark"]];
    if (self.myMarkArray.count < 2) {
        CGFloat tempX = 0.0;
        // 标签
        for (int i = 0; i < self.myMarkArray.count; i++) {
            
            // 进行标签的动态布局
            UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xiaozuMingZiLabel.left + tempX , self.xiaozuMingZiLabel.bottom + 4 * kAdjustParamater, 50, 19 * kAdjustParamater)];
            tempLabel.font = [UIFont systemFontOfSize:11 * kAdjustParamater];
            // 取出内容
            tempLabel.text = self.myMarkArray[i];
            tempLabel.textColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
            tempLabel.textAlignment = NSTextAlignmentCenter;
            CGRect tempRect = tempLabel.frame;
            tempRect.size.width   = [[NetStatusHandle shareHandle] adjustWidth:tempLabel.text size:11 height:19] + 10 * kAdjustParamater;
            tempLabel.frame = tempRect;
            tempX = tempLabel.frame.size.width + 5 * kAdjustParamater;
            // 添加边框
            [tempLabel.layer setBorderWidth:1];
            tempLabel.layer.borderColor = [[UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1] CGColor];
            [self.contentView addSubview:tempLabel];
        }

    } else {
        CGFloat tempX = 0.0;
        // 标签
        for (int i = 0; i < 2; i++) {
            
            // 进行标签的动态布局
            UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.xiaozuMingZiLabel.left + tempX , self.xiaozuMingZiLabel.bottom + 4 * kAdjustParamater, 50, 19 * kAdjustParamater)];
            tempLabel.font = [UIFont systemFontOfSize:11 * kAdjustParamater];
            // 取出内容
            tempLabel.text = self.myMarkArray[i];
            tempLabel.textColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
            tempLabel.textAlignment = NSTextAlignmentCenter;
            CGRect tempRect = tempLabel.frame;
            tempRect.size.width   = [[NetStatusHandle shareHandle] adjustWidth:tempLabel.text size:11 height:19] + 10 * kAdjustParamater;
            tempLabel.frame = tempRect;
            tempX = tempLabel.frame.size.width + 5 * kAdjustParamater;
            // 添加边框
            [tempLabel.layer setBorderWidth:1];
            tempLabel.layer.borderColor = [[UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1] CGColor];
            [self.contentView addSubview:tempLabel];
        }

    }
       // 小组介绍
    self.sampleIntroduceLabel.text = model.introduceGroup;
    // 小组头像
    self.groupImageV.image = [UIImage imageNamed:model.groupImage];
    // 小组名称
    self.groupNameLabel.text = model.groupName;
    CGRect newRect = self.groupNameLabel.frame;
    newRect.size.width = [[NetStatusHandle shareHandle] adjustWidth:self.groupNameLabel.text size:12 height:11];
    self.groupNameLabel.frame = newRect;

}


@end
